package com.koron.css2.meterService.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.meterService.mapper.MsInfoChangeDetailMapper;
import com.koron.css2.meterService.mapper.MsInfoChangeMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 水表变更删除
 * @author bin
 *
 */
public class WmChgDelete implements ServerInterface{
	
	private static Logger log = LogManager.getLogger(WmChgDelete.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<Void> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "删除成功", Void.class);
		try {
			String id = JsonUtils.objectToPojo(req.getData(), String.class);
			MsInfoChangeMapper mapper = factory.getMapper(MsInfoChangeMapper.class);
			MsInfoChangeDetailMapper detailMapper = factory.getMapper(MsInfoChangeDetailMapper.class);
			int iCount = mapper.deleteById(id);
			if(iCount > 0) {
				detailMapper.deleteByChangeId(id);
			}
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("删除失败");
			log.error(e.getMessage(), e);
		}
		return info;
	}


}
